require "lib/timus_access"
require "lib/uva_access"
class AdminController < ApplicationController
  before_filter :store_location
  before_filter :login_required
  
  def authorized?
    admin?
  end
  
  def index
  end
  
  def load_source
    source_list = Source.find(:all)
    source_modules = []
    source_list.reverse.each do |s|
      source_modules << s.name.constantize.load_problems
    end
    redirect_to :action => "index"
  end
  
  def start_get
    source_list = Source.find(:all)
    source_modules = []
    source_list.each do |s|
      source_modules << s.name.constantize.new
    end

    Thread.new do
      while true
        begin   
          source_modules.each do |s|
            s.get
          end
        rescue Exception => e
          puts "THERE WAS AN EXCEPTION THROW!!!"
          puts e.inspect
        end
        sleep(3)
      end
    end
    redirect_to :action => "index"
  end
  
  
end
